package cn.chinaelink.im.mcvboot.controller.api;

import cn.chinaelink.im.mcvboot.vo.menu.MenuMetaVo;
import cn.chinaelink.im.mcvboot.vo.menu.MenuVo;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@Slf4j
@RequestMapping("/api/user")
public class UserController {
    @RequestMapping("/info")
    @ResponseBody
    public JSONObject info(){
        JSONObject userInfoJson = new JSONObject();

        userInfoJson.put("id", "4291d7da9005377ec9aec4a71ea837f");
        userInfoJson.put("name", "天野远子");
        userInfoJson.put("username", "admin");
        userInfoJson.put("password", "");
        userInfoJson.put("avatar", "/avatar2.jpg'");
        userInfoJson.put("status", 1);
        userInfoJson.put("telephone", "");
        userInfoJson.put("lastLoginIp", "27.154.74.117");
        userInfoJson.put("lastLoginTime", 1534837621348L);
        userInfoJson.put("creatorId", "admin'");
        userInfoJson.put("createTime", 1497160610259L);
        userInfoJson.put("merchantCode", "TLif2btpzg079h15bk'");
        userInfoJson.put("deleted", 0);
        userInfoJson.put("roleId", "admin'");

        JSONObject roleObj = new JSONObject();
        roleObj.put("id","admin");
        roleObj.put("name","管理员");
        roleObj.put("describe","拥有所有权限");
        roleObj.put("status", 1);
        roleObj.put("creatorId","system");
        roleObj.put("createTime",1497160610259L);
        roleObj.put("deleted", 0);
        JSONArray permissionArray = new JSONArray();
        JSONObject permission1 = new JSONObject();
        permission1.put("roleId","admin");
        permission1.put("permissionId","dashboard");
        permission1.put("permissionName","仪表盘");
        permission1.put("actions","[{\"action\":\"add\",\"defaultCheck\":false,\"describe\":\"新增\"},{\"action\":\"query\",\"defaultCheck\":false,\"describe\":\"查询\"},{\"action\":\"get\",\"defaultCheck\":false,\"describe\":\"详情\"},{\"action\":\"update\",\"defaultCheck\":false,\"describe\":\"修改\"},{\"action\":\"delete\",\"defaultCheck\":false,\"describe\":\"删除\"}]");

        JSONArray actionEntitySet = new JSONArray();
        JSONObject actionEntity1 = new JSONObject();
        actionEntity1.put("action", "add");
        actionEntity1.put("describe", "新增");
        actionEntity1.put("defaultCheck", false);
        actionEntitySet.add(actionEntity1);

        JSONObject actionEntity2 = new JSONObject();
        actionEntity2.put("action", "query");
        actionEntity2.put("describe", "查询");
        actionEntity2.put("defaultCheck", false);
        actionEntitySet.add(actionEntity2);

        JSONObject actionEntity3 = new JSONObject();
        actionEntity3.put("action", "get");
        actionEntity3.put("describe", "详情");
        actionEntity3.put("defaultCheck", false);
        actionEntitySet.add(actionEntity3);

        JSONObject actionEntity4 = new JSONObject();
        actionEntity4.put("action", "update");
        actionEntity4.put("describe", "修改");
        actionEntity4.put("defaultCheck", false);
        actionEntitySet.add(actionEntity4);

        JSONObject actionEntity5 = new JSONObject();
        actionEntity5.put("action", "delete");
        actionEntity5.put("describe", "删除");
        actionEntity5.put("defaultCheck", false);
        actionEntitySet.add(actionEntity5);

        permission1.put("actionEntitySet", actionEntitySet);
        permission1.put("actionList", null);
        permission1.put("dataAccess", null);
        permissionArray.add(permission1);

        JSONObject permission2 = new JSONObject();
        permission2.put("roleId","admin");
        permission2.put("permissionId","exception");
        permission2.put("permissionName","异常页面权限");
        permission2.put("actions","[{\"action\":\"add\",\"defaultCheck\":false,\"describe\":\"新增\"},{\"action\":\"query\",\"defaultCheck\":false,\"describe\":\"查询\"},{\"action\":\"get\",\"defaultCheck\":false,\"describe\":\"详情\"},{\"action\":\"update\",\"defaultCheck\":false,\"describe\":\"修改\"},{\"action\":\"delete\",\"defaultCheck\":false,\"describe\":\"删除\"}]");

        JSONArray actionEntitySet2 = new JSONArray();
        JSONObject actionEntity21 = new JSONObject();
        actionEntity21.put("action", "add");
        actionEntity21.put("describe", "新增");
        actionEntity21.put("defaultCheck", false);
        actionEntitySet2.add(actionEntity21);

        JSONObject actionEntity22 = new JSONObject();
        actionEntity22.put("action", "query");
        actionEntity22.put("describe", "查询");
        actionEntity22.put("defaultCheck", false);
        actionEntitySet2.add(actionEntity22);

        JSONObject actionEntity23 = new JSONObject();
        actionEntity23.put("action", "get");
        actionEntity23.put("describe", "详情");
        actionEntity23.put("defaultCheck", false);
        actionEntitySet2.add(actionEntity23);

        JSONObject actionEntity24 = new JSONObject();
        actionEntity24.put("action", "update");
        actionEntity24.put("describe", "修改");
        actionEntity24.put("defaultCheck", false);
        actionEntitySet2.add(actionEntity24);

        JSONObject actionEntity25 = new JSONObject();
        actionEntity25.put("action", "delete");
        actionEntity25.put("describe", "删除");
        actionEntity25.put("defaultCheck", false);
        actionEntitySet2.add(actionEntity25);

        permission2.put("actionEntitySet", actionEntitySet2);
        permission2.put("actionList", null);
        permission2.put("dataAccess", null);
        permissionArray.add(permission2);
        roleObj.put("permissions", permissionArray);
        userInfoJson.put("role", roleObj);

        JSONObject body = new JSONObject();
        body.put("result", userInfoJson);
        return body;
    }

    @RequestMapping("/nav")
    @ResponseBody
    public JSONObject getUserMenus(){
        List<MenuVo> dataArray = new ArrayList<>();
        MenuVo menu1 = new MenuVo();
        menu1.setId(1);
        menu1.setParentId(0);
        menu1.setName("dashboard");
        menu1.setComponent("RouteView");
        menu1.setRedirect("/dashboard/workplace");
        MenuMetaVo meta1 = new MenuMetaVo();
        meta1.setTitle("menu.dashboard");
        meta1.setIcon("dashboard");
        meta1.setShow(true);
        menu1.setMeta(meta1);
        dataArray.add(menu1);

        MenuVo menu2 = new MenuVo();
        menu2.setId(7);
        menu2.setParentId(1);
        menu2.setName("workplace");
        menu2.setComponent("Workplace");
        MenuMetaVo meta2 = new MenuMetaVo();
        meta2.setTitle("menu.dashboard.monitor");
        meta2.setShow(true);
        menu2.setMeta(meta2);
        dataArray.add(menu2);

        MenuVo menu3 = new MenuVo();
        menu3.setId(3);
        menu3.setParentId(1);
        menu3.setName("monitor");
        menu3.setPath("https://www.baidu.com/");
        MenuMetaVo meta3 = new MenuMetaVo();
        meta3.setTitle("menu.dashboard.workplace");
        meta3.setTarget("_blank");
        meta3.setShow(true);
        menu3.setMeta(meta3);
        dataArray.add(menu3);

        MenuVo menu4 = new MenuVo();
        menu4.setId(2);
        menu4.setParentId(1);
        menu4.setName("Analysis");
        menu4.setComponent("Analysis");
        menu4.setPath("/dashboard/analysis");
        MenuMetaVo meta4 = new MenuMetaVo();
        meta4.setTitle("menu.dashboard.analysis");
        meta4.setShow(true);
        menu4.setMeta(meta4);
        dataArray.add(menu4);

        // Form
        MenuVo menu5 = new MenuVo();
        menu5.setId(10);
        menu5.setParentId(0);
        menu5.setName("form");
        menu5.setComponent("RouteView");
        menu5.setRedirect("/form/base-form");
        MenuMetaVo meta5 = new MenuMetaVo();
        meta5.setTitle("menu.form");
        meta5.setIcon("form");
        menu5.setMeta(meta5);
        dataArray.add(menu5);

        MenuVo menu6 = new MenuVo();
        menu6.setId(6);
        menu6.setParentId(10);
        menu6.setName("basic-form");
        menu6.setComponent("BasicForm");
        MenuMetaVo meta6 = new MenuMetaVo();
        meta6.setTitle("menu.form.basic-form");
        menu6.setMeta(meta6);
        dataArray.add(menu6);

        MenuVo menu7 = new MenuVo();
        menu7.setId(5);
        menu7.setParentId(10);
        menu7.setName("step-form");
        menu7.setComponent("StepForm");
        MenuMetaVo meta7 = new MenuMetaVo();
        meta7.setTitle("menu.form.step-form");
        menu7.setMeta(meta7);
        dataArray.add(menu7);

        MenuVo menu8 = new MenuVo();
        menu8.setId(4);
        menu8.setParentId(10);
        menu8.setName("advanced-form");
        menu8.setComponent("AdvanceForm");
        MenuMetaVo meta8 = new MenuMetaVo();
        meta8.setTitle("menu.form.advanced-form");
        menu8.setMeta(meta8);
        dataArray.add(menu8);

        // List
        MenuVo menu9 = new MenuVo();
        menu9.setId(10010);
        menu9.setParentId(0);
        menu9.setName("list");
        menu9.setComponent("RouteView");
        menu9.setRedirect("/list/table-list");
        MenuMetaVo meta9 = new MenuMetaVo();
        meta9.setTitle("menu.list");
        meta9.setIcon("table");
        meta9.setShow(true);
        menu9.setMeta(meta9);
        dataArray.add(menu9);

        MenuVo menu10 = new MenuVo();
        menu10.setId(10011);
        menu10.setParentId(10010);
        menu10.setName("table-list");
        menu10.setComponent("TableList");
        menu10.setPath("/list/table-list/:pageNo([1-9]\\d*)?");
        MenuMetaVo meta10 = new MenuMetaVo();
        meta10.setTitle("menu.list.table-list");
        meta10.setShow(true);
        menu10.setMeta(meta10);
        dataArray.add(menu10);

        MenuVo menu11 = new MenuVo();
        menu11.setId(10012);
        menu11.setParentId(10010);
        menu11.setName("basic-list");
        menu11.setComponent("StandardList");
        MenuMetaVo meta11 = new MenuMetaVo();
        meta11.setTitle("menu.list.basic-list");
        meta11.setShow(true);
        menu11.setMeta(meta11);
        dataArray.add(menu11);

        MenuVo menu12 = new MenuVo();
        menu12.setId(10013);
        menu12.setParentId(10010);
        menu12.setName("card");
        menu12.setComponent("CardList");
        MenuMetaVo meta12 = new MenuMetaVo();
        meta12.setTitle("menu.list.card-list");
        meta12.setShow(true);
        menu12.setMeta(meta12);
        dataArray.add(menu12);

        MenuVo menu13 = new MenuVo();
        menu13.setId(10014);
        menu13.setParentId(10010);
        menu13.setName("search");
        menu13.setComponent("SearchLayout");
        menu13.setRedirect("/list/search/article");
        MenuMetaVo meta13 = new MenuMetaVo();
        meta13.setTitle("menu.list.search-list");
        meta13.setShow(true);
        menu13.setMeta(meta13);
        dataArray.add(menu13);

        MenuVo menu14 = new MenuVo();
        menu14.setId(10015);
        menu14.setParentId(10014);
        menu14.setName("article");
        menu14.setComponent("SearchArticles");
        MenuMetaVo meta14 = new MenuMetaVo();
        meta14.setTitle("menu.list.search-list.articles");
        meta14.setShow(true);
        menu14.setMeta(meta14);
        dataArray.add(menu14);

        MenuVo menu15 = new MenuVo();
        menu15.setId(10016);
        menu15.setParentId(10014);
        menu15.setName("project");
        menu15.setComponent("SearchProjects");
        MenuMetaVo meta15 = new MenuMetaVo();
        meta15.setTitle("menu.list.search-list.projects");
        meta15.setShow(true);
        menu15.setMeta(meta15);
        dataArray.add(menu15);

        MenuVo menu16 = new MenuVo();
        menu16.setId(10017);
        menu16.setParentId(10014);
        menu16.setName("application");
        menu16.setComponent("SearchApplications");
        MenuMetaVo meta16 = new MenuMetaVo();
        meta16.setTitle("menu.list.search-list.applications");
        meta16.setShow(true);
        menu16.setMeta(meta16);
        dataArray.add(menu16);

        // Gantt
        MenuVo menu17 = new MenuVo();
        menu17.setId(10018);
        menu17.setParentId(0);
        menu17.setName("gantt");
        menu17.setComponent("RouteView");
        menu17.setRedirect("/gantt/resourceGantt");
        MenuMetaVo meta17 = new MenuMetaVo();
        meta17.setTitle("menu.gantt");
        meta17.setIcon("table");
        meta17.setShow(true);
        menu17.setMeta(meta17);
        dataArray.add(menu17);

        MenuVo menu18 = new MenuVo();
        menu18.setId(10019);
        menu18.setParentId(10018);
        menu18.setName("resourceGantt");
        menu18.setComponent("ResourceGantt");
        menu18.setPath("/gantt/resourceGantt");
        MenuMetaVo meta18 = new MenuMetaVo();
        meta18.setTitle("menu.gantt.resourceGantt");
        meta18.setShow(true);
        menu18.setMeta(meta18);
        dataArray.add(menu18);

        MenuVo menu19 = new MenuVo();
        menu19.setId(10020);
        menu19.setParentId(10018);
        menu19.setName("resourceGanttDayHour");
        menu19.setComponent("ResourceGanttDayHour");
        menu19.setPath("/gantt/resourceGanttDayHour");
        MenuMetaVo meta19 = new MenuMetaVo();
        meta19.setTitle("menu.gantt.resourceGantt.dayhour");
        meta19.setShow(true);
        menu19.setMeta(meta19);
        dataArray.add(menu19);

        MenuVo menu20 = new MenuVo();
        menu20.setId(10021);
        menu20.setParentId(10018);
        menu20.setName("orderGantt");
        menu20.setComponent("OrderGantt");
        menu20.setPath("/gantt/orderGantt");
        MenuMetaVo meta20 = new MenuMetaVo();
        meta20.setTitle("menu.gantt.orderGantt");
        meta20.setShow(true);
        menu20.setMeta(meta20);
        dataArray.add(menu20);

        JSONObject body = new JSONObject();
        body.put("result", dataArray);
        return body;
    }
}

